<!DOCTYPE html PUBLIC>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>填写赛事详情</title>
    <link href="$!webPath/css/template.css" rel="stylesheet" type="text/css"/>
    <link href="$!webPath/css/jquery-ui-1.8.22.custom.css" type="text/css" rel="stylesheet">
    <script src="$!webPath/js/jquery.min.js"></script>
    <script src="$!webPath/js/jquery-ui-1.8.21.js"></script>
    <script src="$!webPath/js/laydate/laydate.js"></script>
    <script src="$!webPath/js/jquery.form1.js"></script>

    <style type="text/css">
        label.error {
            color: #F00;
            margin-left: 3px;
        }

        input.error {
            border: 2px solid #F00;
        }
    </style>
</head>
<body>
<div class="header_nav">
    <iframe name="content_frame" src="$!webPath/admin/nav" marginwidth=0 marginheight=0  frameborder=0 width=100% height=80/></iframe>
    <div class="cont_right"><a href="$!webPath/login">注销</a></div>
</div>
<div class="cont">
    <h3 class="seth">编辑</h3>
    <div class="nav_list">
        <ul id="ul_table">
            <li><a href="$!webPath/admin/matchList?size=10&page=0"><b>赛事列表</b></a></li>
            <li><a href="javascript:void(0);" class="this"><b>编辑</b></a></li>
        </ul>
    </div>
    <div class="adddetail">
        <form action="$!webPath/admin/" method="post" name="theForm" id="theForm">

            <div class="edit">
                <div class="setcont editul">

                    <ul class="set1">
                        <li class="setcont_bg">主队得分</li>
                        <li>
                            <span class="webname">
                                <input id="homeScore" name="homeScore" value="$!match.homeScore" type="text" size="30">
                            </span>
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">客队得分</li>
                        <li>
                        <span class="webname">
                          <input id="visitingScore" name="visitingScore" value="$!match.visitingScore" type="text" size="30">
                        </span>
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">比赛结果</li>
                        <li>
                        <span class="webname">
                            #if($!match.matchResult==0)
                            <select name="matchResult" class="matchResult">
                                <option value="0" selected>平局</option>
                                <option value="1">主队胜</option>
                                <option value="2">主队负</option>
                            </select>
                            #elseif($!match.matchResult==1)
                            <select name="matchResult" class="matchResult">
                                <option value="0" >平局</option>
                                <option value="1" selected>主队胜</option>
                                <option value="2">主队负</option>
                            </select>
                            #elseif($!match.matchResult==2)
                            <select name="matchResult" class="matchResult">
                                <option value="0" >平局</option>
                                <option value="1" >主队胜</option>
                                <option value="2" selected>主队负</option>
                            </select>
                            #else
                            <select name="matchResult" class="matchResult">
                                <option selected>--请选择--</option>
                                <option value="0" >平局</option>
                                <option value="1" >主队胜</option>
                                <option value="2" >主队负</option>
                            </select>
                            #end
                        </span>
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">比赛时间</li>
                        <li>
                        <span class="webname">
                            <input class="laydate-icon" name="matchTime" id="matchTime"  value="$!match.matchTime" size="30">
                        </span>
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">主队</li>
                        <li>
                        <span class="webname">
                          <!--<input id="homeTeamId" value="$!match.homeTeamId" type="text" size="30">-->
                            <select name="homeTeamId" id="hometeam">
                                <option>--请选择主队--</option>
                            </select>
                        </span>
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">客队</li>
                        <li>
                        <span class="webname">
                          <!--<input name="visityTeamId" id="visityTeamId" value="$!match.visityTeamId" type="text" size="30">-->
                            <select name="visityTeamId" id="visityTeamId">
                                <option>--请选择客队--</option>
                            </select>
                        </span>
                        </li>
                    </ul>
                </div>
            </div>

            <input name="activityId" id="activityId" value="$!activityId" type="hidden" size="30">
            <input name="matchId" id="matchId" value="$!match.id" type="hidden" size="30">

        </form>
        <div class="submit">
            <span class="pad120">
            <input name="save" type="button" value="提交" id="saveForm">
            </span>
        </div>
    </div>
</div>
<script>
    $(function(){
//        getUrlParam = function (name) {
//            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
//            var r = window.location.search.substr(1).match(reg);
//            if (r != null) return decodeURI(r[2]); return null;
//        }
        laydate({
            elem: '#matchTime',
            istime:true,
            format:'YYYY-MM-DD hh:mm:ss'
        })
        //activityId=getUrlParam('activityId');
        $.ajax({
            url:'$!webPath/admin/findAllTeams',
            type:'get',
            success: function (data) {
                console.log(data.data);
                var str='';
                var visityTeam='';
                console.log('teamid==========='+'$!match.visityTeamId')
                $.each(data.data,function (index,item) {
                    if('$!match.homeTeamId'==item.id){
                        str+='<option value="'+item.id+'" selected>'+item.name+'</option>';
                    }else{
                        str+='<option value="'+item.id+'">'+item.name+'</option>';
                    }
                    if('$!match.visitingTeamId'==item.id){
                        visityTeam+='<option value="'+item.id+'" selected>'+item.name+'</option>';
                    }else{
                        visityTeam+='<option value="'+item.id+'">'+item.name+'</option>';
                    }
                })
                $('#hometeam').append(str);
                $('#visityTeamId').append(visityTeam);
            }
        })
    })
    $('#saveForm').click(function(){
        var matchId = $('#matchId').val();
        var homeScore=$('#homeScore').val();
        var visitingScore=$('#visitingScore').val();
        var matchResult=$('.matchResult option:selected').val();
        var matchTime=$('#matchTime').val();
        var activityId=activityId;
        var homeTeamId=$('#hometeam option:selected').val();
        var visityTeamId=$('#visityTeamId option:selected').val();
        if(homeScore==''||visitingScore==''||matchResult==''||matchTime==''||homeTeamId==''||visityTeamId==''){
            alert('每一项都不能为空');
            return false;
        }
        //$('#activityId').val(activityId);
//        var get_data={
//            matchId:'$!match.id',
//            homeScore:homeScore,
//            visitingScore:visitingScore,
//            matchResult:matchResult,
//            matchTime:matchTime,
//            activityId:activityId1,
//            homeTeamId:homeTeamId,
//            visityTeamId:visityTeamId
//        }
        $('#theForm').ajaxSubmit({
            url:'$!webPath/admin/addMatch',
            type:'post',
            success: function () {
                window.location.href = "$!webPath/admin/matchList?activityId="+"$!activityId";
            },
            error:function(){
                alert('失败');
            }
        })
    })

</script>
</body>
</html>
